#include <stdio.h>
#include <stdlib.h>
struct Stu{
	int num;
	float score;
	struct Stu* next;
};
typedef struct Stu LinkNode;
typedef struct Stu* LinkList;
LinkList CreateList(){
	LinkList head,p,q;
	int tmp;
	float mark;
	head=p=q=NULL;
	while(1)
	{
		scanf("%d %f",&tmp,&mark);
		if(tmp>0)
		{
			q=(LinkList)malloc(sizeof(LinkNode));
			q->num=tmp;
			q->score=mark;
			q->next=NULL;
		}
		else
			break;
		if(!head)
			head=p=q;
		else
			p->next=q;
		p=q;
	}
	return head;
}

LinkList AddNode(LinkList head,int n1,float n2)
{
	LinkList p=NULL,q=NULL;
	p=head;
	q=(LinkList)malloc(sizeof(LinkNode));
	q->num=n1;
	q->score=n2;
	q->next=NULL;
	if(!head)
		head=q;
	else{
		while(p->next!=NULL)
			p=p->next;
		p->next=q;
	}
	return head;
	}

LinkList CompareNode(LinkList head1,LinkList head2,LinkList head3)
{
	LinkList p=head1,q=head2;
	head3=NULL;
	if(head1==NULL&&head2)
	{
		head3=head2;
		return head3;
	}
	else if(head2==NULL&&head1)
	{
		head3=head1;
		return head3;
	}
	else if(head1==NULL&&head2==NULL)
	{
		head3=NULL;
		return head3;
	}
	else{
		while(p!=NULL&&q!=NULL)
		{
			if(p->num<q->num)
			{
				head3=AddNode(head3,p->num,p->score);
				p=p->next;
			}
			else 
			{
				head3=AddNode(head3,q->num,q->score);
				q=q->next;
			}
		}
	}
	if(p!=NULL)
		while(p)
		{
			head3=AddNode(head3,p->num,p->score);
			p=p->next;
		}
	if(q!=NULL)
	while(q)
	{
		head3=AddNode(head3,q->num,q->score);
		q=q->next;
	}
	return head3;
}
void PrintList(LinkList head)
{
	LinkList ptr=head;
	while(ptr)
	{
		printf("%d\t%f\n",ptr->num,ptr->score);
		ptr=ptr->next;
	}
}

void FreeList(LinkList head)
{
	LinkList p,q;
	p=q=head;
	while(p){
		q=p->next;
		free(p);
		p=q;
	}
}

int main()
{
	LinkList head1,head2,head3=NULL;
	head1=CreateList();
	head2=CreateList();
	head3=CompareNode(head1,head2,head3);
	PrintList(head3);
	if(head3!=head2&&head3!=head1)
		FreeList(head3);
	FreeList(head1);
	FreeList(head2);
	return 0;
}
